<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/pages/secondHand.css" />
	</head>

	<body>
		<div id="app" class="content">
			<header class="header" v-text="detailData.usecTitle"></header>
			<div class="price m-t-10">
				<span class="font-12">￥</span>
				<span v-text="detailData.usecPrice"></span>
			</div>
			<div class="user">
				<img class="user-img" :src="detailData.icon || '../../../images/user/moren.png' ">
				<div class="user-desc">
					<span class="name" v-text="detailData.periNickname || '小区住户' "></span>
					<span class="time">发布于：{{detailData.usecCD | timeago}}</span>
				</div>
			</div>
			<div class="details" v-text="detailData.usecdDetails"></div>

			<div class="list-img">
				<div v-for="item in detailData.filesList">
					<img :src="item.filesPath">
				</div>
			</div>
			<div class="preview">{{detailData.pageView}}人预览</div>
			<div class="bottom-btn">
				<div class="collect" @click="collectTap(detailData.isCollecting)">
					<img class="collect-icon" :src="detailData.isCollecting==0?'../images/details/shou_no.png' : '../images/details/shou.png' ">
					<span v-text="detailData.isCollecting==0?'加入收藏':'已收藏'"></span>
				</div>
				<div class="relation" @click="wantClick">我想要</div>
			</div>
		</div>
		<script src="../../../js/Width.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/Util.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
		<script type="text/javascript">
			mui.init({
				beforeback: function() {
					//获得列表界面的webview
					var list = plus.webview.currentWebview().opener();
					//触发列表界面的自定义事件（refresh）,从而进行数据刷新
					mui.fire(list, 'collectCallback');
					//返回true，继续页面关闭逻辑
					return true;
				}
			})
			mui.plusReady(function() {
				if (!mui.os.android) {
					FastClick.attach(document.body);
				}

				var self = plus.webview.currentWebview()
				app.detailID = self.detailID;
				
				if (self.my == 0) {
					self.setStyle({
						titleNView: {
							buttons: [{
								text: "删除",
								color: '#4FA7E6',
								float: 'right',
								fontSize: '16px',
								onclick: app.onDelete
							}]
						}
					})
				}

				GetUsedCommodityDetails(self.detailID)
			})
			var app = new Vue({
				el: "#app",
				data: {
					detailID: '',
					detailData: {}
				},
				filters: {
					timeago: function(value) {
						return Util.timeago(value)
					}
				},
				methods: {
					collectTap: function(type) {
						var id = this.detailData.usecID
						if (type == 0) {
							this.detailData.isCollecting = 1
							Util.AddCollecting(id, "UsedCommodity")
						} else if (type == 1) {
							this.detailData.isCollecting = 0
							Util.CancelCollecting(id, "UsedCommodity")
						}
					},
					wantClick: function() {
						var data = {
							periNickname: this.detailData.periNickname,
							icon: this.detailData.icon,
							phone: this.detailData.phone,
							usecTitle: this.detailData.usecTitle,
							usecdDetails: this.detailData.usecdDetails,
							filesPath: this.detailData.filesList[0].filesPath,
							usecPrice: this.detailData.usecPrice
						}
						plus.nativeUI.confirm("本平台仅提供卖家的联系方式，需自行跟卖家商量购买方式", function(e) {
							if (e.index == 0) {
								mui.openWindow({
									url: 'relation.html',
									id: 'relation.html',
									extras: {
										data: data,
									},
									waiting: {
										autoShow: false
									}
								})
							}
						})
					},
					onDelete() {
						var that = this
						var detailID = this.detailID
						plus.nativeUI.confirm("是否确认删除？",function(e){
							if(e.index==0){
								that.isdelete(detailID)
							}
						})
					},
					isdelete(detailID) {
						mui.post(Util.HTTP + 'api/UsedCommodity/DeleteUsedCommodity',{
							usecID: detailID
						},function(res){
							mui.toast(res.message)
							if(res.code==1001){
								setTimeout(function(){
									mui.back()
									var list = plus.webview.currentWebview().opener();
									//触发列表界面的自定义事件（refresh）,从而进行数据刷新
									mui.fire(list, 'onDelete');
									//返回true，继续页面关闭逻辑
									return true;
								},1000)
							}
						})
					}
				}
			})

			function GetUsedCommodityDetails(usecID) {
				mui.post(Util.HTTP + 'api/UsedCommodity/GetUsedCommodityDetails', {
					usecID: usecID,
					userID: Util.getState('$state').userID
				}, function(res) {
					if (res.code == 1001) {
						app.detailData = res.data
					} else {
						mui.toast(res.message)
					}
				})
			}
		</script>
	</body>

</html>
